var _setting = {
    web_path: "http://localhost:955"
};

$(function () {

    //Base认证
    var Auth_Base = "Basic " + new Base64().encode("system" + ":" + "123456");
    $.ajaxSetup({
        // 将XHR对象的withCredentials设为true
        headers: {
            Authorization: Auth_Base
        }
    });
    $("#loginBtn").click(function () {
        var _this = $(this);
        $.ajax({
            url: _setting.web_path + '/oauth/token?grant_type=password',
            type: 'post',
            dataType: 'json',
            crossDomain: true,
            data: $("#loginForm").serialize(),
            success: function (result) {
                console.log(result);
                var jsonString = JSON.stringify(result);
                var token = "access_token=" + result.access_token;
                $("#result").text(jsonString);
                $("#token").val(token);
                setCookie("access_token", result.access_token);
                setCookie("username", $("#username").val());
            }, error: function () {
                _this.text("登录").removeAttr("disabled").removeClass("layui-disabled");
            }

        });
        return false;
    });
});